package com.von.nhcf.controller;

import com.von.nhcf.entity.vo.DetailProjectVO;
import com.von.nhcf.entity.vo.PortalTypeVO;
import com.von.nhcf.entity.vo.ProjectVO;
import com.von.nhcf.service.MysqlProjectService;
import com.von.nhcf.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MysqlProjectController {
    @Autowired
    private MysqlProjectService mysqlProjectService;
    @RequestMapping("/save/project/vo/remote")
    ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId) {
        try {
            mysqlProjectService.saveProject(projectVO, memberId);
            return ResultEntity.successWithoutData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failureWithMsg(e.getMessage());
        }
    }
    @RequestMapping("/get/project/type/vo/remote")
    ResultEntity<List<PortalTypeVO>> getProjectTypeVORemote() {
        try {
            List<PortalTypeVO> portalTypeVO = mysqlProjectService.getPortalTypeVO();
            return ResultEntity.successWithData(portalTypeVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failureWithMsg(e.getMessage());
        }

    }
    @RequestMapping("/get/detail/project/vo/remote/{projectId}")
    ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId") Integer id) {
        try {
            DetailProjectVO detailProjectVO = mysqlProjectService.getDetailProjectVO(id);
            return ResultEntity.successWithData(detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failureWithMsg(e.getMessage());
        }
    }
}
